<template>
  <pageTabelLayout>
    <template #pageHeader>
      <div class="search-form isheader" v-if="headerShow" style="height: 84px">
        <div>
          <a-form
            v-if="tabsKeys == 1 || tabsKeys == 3"
            size="small"
            :model="pageData"
            layout="inline"
          >
            <a-form-item label="单号">
              <a-input
                allow-clear
                :style="{ width: '240px' }"
                class="bacClass"
                v-model="pageData.z"
              />
            </a-form-item>
            <CorporateSectorCascader
              :configCascader="configCascader3"
              @changeCascader="changeCascader3"
            />
            <a-form-item label="仓库">
              <a-select
                popup-container="html"
                class="bacClass"
                :style="{ width: '200px' }"
                v-model="pageData.b"
                allow-clear
              >
                <a-option v-for="item in fhWhList3" :value="item.id">
                  {{ item.warehouseName }}
                </a-option>
              </a-select>
            </a-form-item>
            <a-form-item label="出库类型">
              <a-select
                popup-container="html"
                v-if="tabsKeys == 1"
                :style="{ width: '200px' }"
                class="bacClass"
                v-model="pageData.f"
                allow-clear
              >
                <a-option :value="1">领料出库</a-option>
                <a-option :value="2">调拨单出库</a-option>
              </a-select>
              <a-select
                popup-container="html"
                v-if="tabsKeys == 3"
                :style="{ width: '200px' }"
                class="bacClass"
                v-model="pageData.f"
                allow-clear
              >
                <a-option :value="3">采购退货</a-option>
                <a-option :value="4">采购换货</a-option>
              </a-select>
            </a-form-item>
            <a-form-item v-if="tabsKeys == 1" label="日期">
              <a-range-picker
                popup-container="html"
                :style="{ width: '240px' }"
                class="bacClass"
                @clear="onClear"
                allow-clear
                v-model="pageData.dropDownTime"
              />
            </a-form-item>
          </a-form>
          <a-form v-else-if="tabsKeys == 2" size="small" :model="pageData" layout="inline">
            <a-form-item label="领料单号">
              <a-input
                allow-clear
                :style="{ width: '200px' }"
                class="bacClass"
                placeholder=""
                v-model="pageData.c"
              />
            </a-form-item>
            <a-form-item label="物料编号">
              <a-input
                allow-clear
                :style="{ width: '200px' }"
                class="bacClass"
                placeholder=""
                v-model="pageData.d"
              />
            </a-form-item>
            <a-form-item label="物料名称">
              <a-input
                allow-clear
                :style="{ width: '200px' }"
                class="bacClass"
                placeholder=""
                v-model="pageData.e"
              />
            </a-form-item>
          </a-form>
          <a-form v-if="tabsKeys == 4" size="small" :model="pageData" layout="inline">
            <CorporateSectorCascader
              :configCascader="configCascader4"
              @changeCascader="changeCascader4"
            />
            <a-form-item label="仓库">
              <a-select
                popup-container="html"
                class="bacClass"
                :style="{ width: '200px' }"
                v-model="query.warehouseId"
                allow-clear
                :disabled="!query.firmId"
              >
                <a-option v-for="(item, index) in fhWhList4" :value="item.id" :key="index">
                  {{ item.warehouseName }}
                </a-option>
              </a-select>
            </a-form-item>
            <a-form-item label="物料名称">
              <a-input
                allow-clear
                :style="{ width: '200px' }"
                class="bacClass"
                v-model="query.materialName"
              />
            </a-form-item>
            <a-form-item label="物料编号">
              <a-input
                allow-clear
                :style="{ width: '200px' }"
                class="bacClass"
                v-model="query.materialCode"
              />
            </a-form-item>
          </a-form>
        </div>
        <div>
          <Toolbar
            :items="toolbarList"
            @add="addList"
            @select="selectHandler"
            @add-db="adddbs"
            @del="delSles"
            @audit="audits"
            @oders="redersOut"
            @print="printPdf"
          >
          </Toolbar>
        </div>
      </div>
      <div class="my-divisders">
        <a-divider orientation="center">
          <icon-double-up
            v-if="headerShow"
            @click="headerShow = false"
            :strokeWidth="2"
            :size="18"
          />
          <icon-double-down v-else @click="headerShow = true" :strokeWidth="2" :size="18" />
        </a-divider>
      </div>
    </template>
    <template #pageTabel>
      <a-tabs
        :lazy-load="true"
        :justify="true"
        :default-active-key="tabsKeys"
        @change="tabsChanges"
      >
        <a-tab-pane title="已处理" :key="1">
          <AgGridVuesCopys
            :rowHeight="33"
            :headerHeight="33"
            :suppressCopyRowsToClipboard="true"
            :suppressDragLeaveHidesColumns="true"
            rowSelection="multiple"
            @grid-ready="gridReady"
            @columnResized="onColumnResized"
            @columnMoved="onColumnMoved"
            @columnVisible="onColumnVisible"
            style="height: calc(100% - 45px)"
            :defaultColDef="defaultColDef"
            class="ag-theme-alpine"
            :rowData="tableDataList"
            :columnDefs="tc"
            :localeText="localeText1"
          ></AgGridVuesCopys>
          <paginationCopys
            :page-size-options="pagingList1"
            :total="fySelet2.total"
            show-total
            show-jumper
            show-page-size
            @change="PageSize2"
            @page-size-change="change2"
            style="justify-content: center"
            :page-size="fySelet2.size"
            :current="fySelet2.page"
          />
        </a-tab-pane>
        <a-tab-pane title="领料单待处理" :key="2">
          <AgGridVuesCopys
            :rowHeight="33"
            :headerHeight="33"
            :suppressCopyRowsToClipboard="true"
            :suppressDragLeaveHidesColumns="true"
            rowSelection="multiple"
            @grid-ready="gridReady2"
            @columnResized="onColumnResized2"
            @columnMoved="onColumnMoved2"
            @columnVisible="onColumnVisible2"
            style="height: calc(100% - 45px)"
            :defaultColDef="defaultColDef2"
            class="ag-theme-alpine"
            :rowData="tableDataList2"
            :columnDefs="tc2"
            :localeText="localeText1"
          ></AgGridVuesCopys>
          <paginationCopys
            :page-size-options="pagingList1"
            :total="fySelet.total"
            show-total
            show-jumper
            show-page-size
            @change="PageSize"
            @page-size-change="change"
            style="justify-content: center"
            :page-size="fySelet.size"
            :current="fySelet.page"
          />
        </a-tab-pane>
        <!-- <a-tab-pane title="采购退货" :key="3">
          <AgGridVuesCopys :rowHeight="33" :headerHeight="33" :suppressCopyRowsToClipboard="true" rowSelection="multiple" @grid-ready="gridReady3"
            style="height: 94%" :defaultColDef="defaultColDef2" class="ag-theme-alpine" :rowData="tableDataList3"
            :columnDefs="tc3" :localeText="localeText1"></AgGridVuesCopys>
          <paginationCopys :page-size-options="pagingList1" :total="fySelet3.total" show-total show-jumper show-page-size
            @change="PageSize3" @page-size-change="change3" style="justify-content: center" :page-size="fySelet3.size"
            :current="fySelet3.page" />
        </a-tab-pane> -->
        <a-tab-pane title="以旧换新记录" :key="4">
          <div :style="{ height: '100%' }" style="background: #fff">
            <encapsulation-agrid
              ref="refgridOption"
              :configaggrid="configaggrid"
            ></encapsulation-agrid>
          </div>
        </a-tab-pane>
      </a-tabs>
    </template>
    <a-modal
      v-model:visible="cgOut.visible"
      @before-ok="cgHandleOk"
      @cancel="cadelvs"
      fullscreen
      :mask-closable="false"
    >
      <template #title>
        {{ cgOut.title }}
      </template>
      <AgGridVuesCopys
        :rowHeight="33"
        :headerHeight="33"
        :suppressCopyRowsToClipboard="true"
        :suppressDragLeaveHidesColumns="true"
        rowSelection="multiple"
        @columnResized="onColumnResized"
        @columnMoved="onColumnMoved"
        @columnVisible="onColumnVisible"
        style="height: 70vh; margin-top: 10px"
        :defaultColDef="defaultColDef"
        class="ag-theme-alpine"
        :rowData="cgData"
        :columnDefs="cgColumns"
        :localeText="localeText1"
      ></AgGridVuesCopys>
    </a-modal>
    <a-drawer
      ok-text="保存"
      cancel-text="关闭"
      :drawer-style="{ zIndex: 999 }"
      :mask-closable="false"
      unmount-on-close
      popup-container=".arco-tabs-content"
      :height="'100%'"
      :visible="dbPageDate.showAdd"
      @ok="sideOk"
      placement="bottom"
      @cancel="sideNo"
    >
      <template #title>
        {{ dbPageDate.titles }}
      </template>
      <!-- <div style="min-width: 1500px; overflow: auto;height:100%;"> -->
      <pageTabelLayout>
        <template #pageHeader>
          <a-form ref="formRef" layout="inline" :model="searchData" size="mini">
            <CorporateSectorCascader
              :configCascader="configCascader"
              @changeCascader="changeCascader"
            />
            <a-form-item
              label="发货仓库"
              :rules="[{ required: true, message: '仓库必填' }]"
              field="fhWh"
            >
              <a-select
                popup-container="html"
                class="bacClass"
                :style="{ width: '10rem' }"
                v-model="searchData.fhWh"
                allow-clear
              >
                <a-option v-for="item in fhWhList" :value="item.id + '-' + item.warehouseName">
                  {{ item.warehouseName }}
                </a-option>
              </a-select>
            </a-form-item>
            <CorporateSectorCascader1
              :configCascader="configCascader2"
              @changeCascader="changeCascader2"
            />
            <a-form-item
              label="收货仓库类型"
              :rules="[{ required: true, message: '仓库必填' }]"
              field="shWhType"
            >
              <a-select
                popup-container="html"
                class="bacClass"
                :style="{ width: '10rem' }"
                allow-search
                v-model="searchData.shWhType"
                allow-clear
                @change="whTypeChanges"
              >
                <a-option>五金仓</a-option>
                <a-option>制具仓</a-option>
              </a-select>
            </a-form-item>
            <a-form-item
              label="收货仓库"
              :rules="[{ required: true, message: '仓库必填' }]"
              field="shWh"
            >
              <a-select
                popup-container="html"
                class="bacClass"
                :style="{ width: '10rem' }"
                v-model="searchData.shWh"
                allow-clear
              >
                <a-option v-for="item in shWhList" :value="item.id + '-' + item.warehouseName">
                  {{ item.warehouseName }}
                </a-option>
              </a-select>
            </a-form-item>
          </a-form>

          <a-space style="margin-bottom: 10px">
            <a-button type="primary" @click="addLine" size="mini">新增</a-button>
            <a-button type="primary" @click="delLine" size="mini">删除</a-button>
          </a-space>
        </template>
        <template #pageTabel>
          <AgGridVuesCopys
            :rowHeight="33"
            :headerHeight="33"
            :suppressCopyRowsToClipboard="true"
            :suppressDragLeaveHidesColumns="true"
            rowSelection="multiple"
            @grid-ready="gridtableReadydb"
            @columnResized="onColumnResized"
            @columnMoved="onColumnMoved"
            @columnVisible="onColumnVisible"
            style="height: 100%; margin-top: 10px"
            :defaultColDef="defaultColDef"
            class="ag-theme-alpine"
            :rowData="wlListArray"
            :columnDefs="tableColumnsWl"
            :localeText="localeText1"
          ></AgGridVuesCopys>
        </template>
      </pageTabelLayout>
    </a-drawer>
    <a-modal
      v-model:visible="cgOut.visible2"
      :on-before-ok="cgHandleOk2"
      @cancel="cadelvs2"
      fullscreen
      :mask-closable="false"
    >
      <template #title> 调拨出库修改 </template>
      <a-table :columns="cgColumns2" :data="cgData2" :pagination="false" :bordered="{ cell: true }">
        <template #totalNum="{ record }">
          <a-input-number
            class="bacClass"
            v-model="record.totalNum"
            :max="100000"
            :min="0"
          ></a-input-number>
        </template>
      </a-table>
    </a-modal>
    <a-drawer
      ok-text="保存"
      cancel-text="关闭"
      :drawer-style="{ zIndex: 999 }"
      :mask-closable="false"
      unmount-on-close
      popup-container=".arco-tabs-content"
      :height="'90%'"
      :visible="dbPageDate.showAdd2"
      @ok="sideOk2"
      placement="bottom"
      @cancel="sideNo2"
    >
      <template #title> 新增采购出库 </template>
      <a-form ref="formRef2" size="mini" :model="searchData" layout="inline">
        <CorporateSectorCascader
          ref="corport"
          :configCascader="configCascader"
          @changeCascader="changeCascader"
        />
        <a-form-item label="仓库" :rules="[{ required: true, message: '仓库必填' }]" field="fhWh">
          <a-select
            popup-container="html"
            class="bacClass"
            :style="{ width: '10rem' }"
            v-model="searchData.fhWh"
            allow-clear
          >
            <a-option v-for="item in fhWhList" :value="item.id + '-' + item.warehouseName">
              {{ item.warehouseName }}
            </a-option>
          </a-select>
        </a-form-item>
        <a-form-item
          label="出库类型"
          :rules="[{ required: true, message: '出库类型必填' }]"
          field="infoType"
        >
          <a-select
            popup-container="html"
            v-if="tabsKeys == 3"
            :style="{ width: '200px' }"
            class="bacClass"
            v-model="searchData.infoType"
            allow-clear
          >
            <a-option :value="3">采购退货</a-option>
            <a-option :value="4">采购换货</a-option>
          </a-select>
        </a-form-item>
      </a-form>
      <a-space style="margin-bottom: 10px">
        <a-button type="primary" @click="addLine2" size="mini">新增</a-button>
      </a-space>
      <a-table :columns="cgColumns4" :data="cgData4" :pagination="false" :bordered="{ cell: true }">
        <template #totalNum="{ record }">
          <a-input-number
            class="bacClass"
            v-model="record.totalNum"
            :max="record.inStockNum - record.returnNum"
            :min="0"
          ></a-input-number>
        </template>
        <template #acFighs="{ record }">
          <a-button type="primary" @click="delLine2(record)" size="mini">删除</a-button>
        </template>
      </a-table>
    </a-drawer>
    <a-modal
      fullscreen
      v-model:visible="visibleYl"
      :on-before-ok="handleOks"
      @cancel="handleCancels"
      body-class="modal-full-h"
      :mask-closable="false"
      :render-to-body="false"
    >
      <template #title> {{ xuanZeCaigou }}</template>
      <!-- <div class="cgisDatas">
        <div>
          <span>物料编号:</span>
          <a-input class="bacClass" v-model="materialCode" :style="{ width: '150px' }" allow-clear />
        </div>
        <div>
          <span>物料名称:</span>
          <a-input class="bacClass" v-model="materialName" :style="{ width: '150px' }" allow-clear />
        </div>
        <a-button type="primary" size="mini" @click="cxCgsLists">查询</a-button>
      </div> -->
      <pageTabelLayout ref="wjModalLayout">
        <template #pageHeader>
          <div
            style="width: 100%; display: flex; justify-content: space-between; margin-bottom: 10px"
          >
            <div>
              <span>物料大类:</span>
              <a-select
                popup-container="html"
                class="bacClass"
                v-model="objectOP.bigClassName1"
                @change="bigChange(1)"
                :filter-option="false"
                allow-search
                allow-clear
                @focus="WLfocusSel(1)"
                style="width: 150px"
                @press-enter="Query"
                @search="WLfocusSel(1, $event)"
              >
                <a-option v-for="item in objectOP.bigName1" :key="item.id" :value="item.id">
                  {{ item.bigClassName }}
                </a-option>
              </a-select>
            </div>
            <div>
              <span>物料中类:</span>
              <a-select
                popup-container="html"
                class="bacClass"
                :disabled="!objectOP.bigClassName1"
                v-model="objectOP.bigClassName2"
                @change="bigChange(2)"
                :filter-option="false"
                allow-search
                allow-clear
                @focus="WLfocusSel(2)"
                style="width: 150px"
                @press-enter="Query"
                @search="WLfocusSel(2, $event)"
              >
                <a-option v-for="item in objectOP.bigName2" :key="item.id" :value="item.id">
                  {{ item.middleClassName }}
                </a-option>
              </a-select>
            </div>
            <div>
              <span>物料小类:</span>
              <a-select
                popup-container="html"
                class="bacClass"
                :disabled="!objectOP.bigClassName2"
                v-model="objectOP.bigClassName3"
                :filter-option="false"
                allow-search
                allow-clear
                @focus="WLfocusSel(3)"
                style="width: 150px"
                @search="WLfocusSel(3, $event)"
              >
                <a-option v-for="item in objectOP.bigName3" :key="item.id" :value="item.id">
                  {{ item.subClassName }}
                </a-option>
              </a-select>
            </div>
            <div>
              <span>物料编号:</span>
              <a-select
                popup-container="html"
                class="bacClass"
                :loading="WLloading2"
                @search="WLhandleSearch2"
                v-model="materialCode"
                :filter-option="false"
                allow-search
                allow-clear
                @focus="WLfocusSel2"
                @change="WLhandleCode"
                style="width: 200px"
              >
                <a-option
                  v-for="(item, index) in pageData.codeList"
                  :value="item.materialCode + '——' + item.materialName"
                  :key="index"
                >
                  {{ item['materialCode'] + ' —— ' + item['materialName'] }}
                </a-option>
              </a-select>
            </div>
            <div>
              <span>物料名称:</span>
              <a-select
                popup-container="html"
                class="bacClass"
                :loading="WLloading3"
                @search="WLhandleSearch3"
                v-model="materialName"
                :filter-option="false"
                allow-search
                allow-clear
                @focus="WLfocusSel3"
                @change="WLhandleName"
                style="width: 200px"
              >
                <a-option
                  v-for="(item, index) in pageData.codeList"
                  :value="item.materialCode + '——' + item.materialName"
                  :key="index"
                >
                  {{ item['materialCode'] + ' —— ' + item['materialName'] }}
                </a-option>
              </a-select>
            </div>
            <div>
              <span>规格:</span>
              <a-select
                popup-container="html"
                class="bacClass"
                :loading="WLloading4"
                @search="WLhandleSearch4"
                v-model="specName"
                :filter-option="false"
                allow-search
                allow-clear
                @focus="WLfocusSel4"
                style="width: 200px"
              >
                <a-option v-for="(item, index) in pageData.specList" :key="index">
                  {{ item.specName }}
                </a-option>
              </a-select>
            </div>
            <a-button type="primary" size="mini" @click="cxCgsLists">查询</a-button>
          </div>
        </template>
        <template #pageTabel>
          <AgGridVuesCopys
            v-if="xuanZeCaigou == '选择采购单'"
            :rowHeight="33"
            :headerHeight="33"
            :suppressCopyRowsToClipboard="true"
            :suppressDragLeaveHidesColumns="true"
            rowSelection="multiple"
            @columnResized="onColumnResized"
            @columnMoved="onColumnMoved"
            @columnVisible="onColumnVisible"
            style="height: calc(100% - 45px)"
            :defaultColDef="defaultColDef"
            class="ag-theme-alpine"
            :rowData="cgData4"
            :columnDefs="cgColumns4"
            :localeText="localeText1"
          ></AgGridVuesCopys>
          <AgGridVuesCopys
            v-if="xuanZeCaigou == '选择五金库存'"
            :rowHeight="33"
            :headerHeight="33"
            :suppressCopyRowsToClipboard="true"
            :suppressDragLeaveHidesColumns="true"
            rowSelection="multiple"
            @grid-ready="gridtableReadywj"
            @columnResized="onColumnResized"
            @columnMoved="onColumnMoved"
            @columnVisible="onColumnVisible"
            style="height: calc(100% - 45px)"
            :defaultColDef="defaultColDef"
            class="ag-theme-alpine"
            :rowData="wlListXqs"
            :columnDefs="cgColumns5"
            :localeText="localeText1"
          ></AgGridVuesCopys>
          <paginationCopys
            :page-size-options="pagingList1"
            :total="fySelet4.total"
            show-total
            show-jumper
            show-page-size
            @change="PageSize4"
            @page-size-change="change4"
            style="justify-content: center; margintop: 20px"
            :page-size="fySelet4.size"
            :current="fySelet4.page"
            popup-container="html"
          />
        </template>
      </pageTabelLayout>
    </a-modal>
    <a-modal v-model:visible="visiblecg" ok-text="打印" @ok="print1" :width="800">
      <template #title> 打印入库单 </template>
      <div id="dyy2" style="height: 100%" v-for="(item, index) in pageData.dataList" :key="index">
        <div class="TTou">
          <div class="TTou1">
            <oneCode :value="item.title.order_no"></oneCode>
          </div>
          <div class="TTou2">
            <div
              ><b><span style="font-size: 20px">佛山市巨丰盛布业有限公司</span></b></div
            >
            <div
              ><b
                ><span style="font-size: 20px">{{ item.title.companyName }}五金仓库出库单</span></b
              ></div
            >
          </div>
        </div>

        <div class="DivFit" style="margin-top: 15px">
          <div><span>领料单位：</span>{{ item.title.pickUnit }}</div>
          <div><span>出库日期：</span>{{ item.title.printDate }}</div>
          <div><span>出库类型：</span>{{ item.title.pickType }}</div>
        </div>
        <table class="isTable">
          <tr>
            <th>产品编号</th>
            <th>产品名称</th>
            <th>规格</th>
            <th>单位</th>
            <th>数量</th>
          </tr>
          <tr v-for="(items, key, index) in item.material" :key="index">
            <td>{{ items['material_code'] }}</td>
            <td>{{ items['material_name'] }}</td>
            <td>{{ items['specification'] }}</td>
            <td>{{ items['unit'] }}</td>
            <td>{{ items['total_num'] }}</td>
          </tr>
          <tr>
            <th colspan="4">合计</th>
            <th>{{ item.title.totalNum }}</th>
          </tr>
        </table>
        <div class="DivFit" style="margin-top: 15px">
          <div><span>部门名称: </span>{{ item.title.departmentName }}</div>
          <div><span>领料员: </span>{{ item.title.pickPerson }}</div>
          <div><span>制单人: </span>{{ item.title.createName }}</div>
          <div><span>制单日期: </span>{{ item.title.createTime }}</div>
        </div>
      </div>
    </a-modal>
    <a-drawer
      ok-text="保存"
      cancel-text="关闭"
      :drawer-style="{ zIndex: 9999 }"
      height="91vh"
      placement="bottom"
      :visible="pageData.showAdd1"
      unmountOnClose
      @ok="save1"
      @cancel="pageData.showAdd1 = false"
    >
      <template #title> 选择编号 </template>
      <div :style="{ height: '100%', padding: '10px' }" style="background: #fff">
        <encapsulation-agrid
          ref="refgridOption1"
          :configaggrid="configaggrid1"
        ></encapsulation-agrid>
      </div>
    </a-drawer>
  </pageTabelLayout>
</template>
<script setup lang="ts">
  import { ref } from 'vue'
  import oneCode from '@/components/Barcode/index.vue'
  import printJS from 'print-js'
  import { post, get } from '@/api/http'
  import { localeText } from '@/api/aggridZw'
  
  import Toolbar from '@/components/Toolbar.vue'
  import { Message, Modal } from '@arco-design/web-vue'
  import CorporateSectorCascader from '@/components/corporateSectorCascader/inde.vue'
  import CorporateSectorCascader1 from '@/components/corporateSectorCascader1/index.vue'
  import dayjs from 'dayjs'
  import WHService from '@/service/wh'
  import usePermission from '@/store/modules/permission'
  import { pagingList } from '@/api/paging'
  import { tableColumns, tableColumns1 } from './OrderDeliveryList2'
  import { ElMessage, ElMessageBox } from 'element-plus'
  import { saveOrUpdateGridState as saveOrUpdateGridState01 } from '@/hooks/useGridState'
  import { saveOrUpdateGridState as saveOrUpdateGridState02 } from '@/hooks/useGridState'
  import setTableTotalRow from '@/utils/setTableTotalRow.ts'
  const pagingList1: any = ref(pagingList)
  const permissionStore = usePermission()
  const gridtableOptiondb = ref()
  const gridtableReadydb = (params: any) => {
    gridtableOptiondb.value = params.api
  }
  const pageData: any = reactive({
    a: '',
    b: '',
    c: '',
    d: '',
    e: '',
    f: '',
    g: '',
    z: '',
    dropDownTime: [dayjs().format('YYYY-MM-DD'), dayjs().format('YYYY-MM-DD')],
    showAdd_DY: false,
    dataList: [],
    isEdit: false,
    showAdd1: false,
    CheckNumberList: {},
    bigName: [],
    samllName: [],
    codeList: [],
    specList: [],
    wlNameList: [],
  })
  const toolbarList: any = ref([
    `${permissionStore.hasPermisson('yjcck.yclcx') ? '查询' : ''}`,
    `${permissionStore.hasPermisson('yjcck.xzdbd') ? '新建调拨单' : ''}`,
    `${permissionStore.hasPermisson('yjcck.yclsh') ? '审核' : ''}`,
    `${permissionStore.hasPermisson('yjcck.yclsc') ? '删除' : ''}`,
    `${permissionStore.hasPermisson('yjcck.yclsh') ? '打印' : ''}`,
  ])
  let refgridOption1 = ref<any>()
  let oneDayTime: any = ref([dayjs().format('YYYY-MM-DD'), dayjs().format('YYYY-MM-DD')])
  let configaggrid1 = ref({
    url: 'wms/ironwareStockInfo/getListByOut', //接口路径
    queryData: {
      materialCode: pageData.CheckNumberList.materialCode,
      warehouseId: pageData.CheckNumberList.warehouseId,
    },
    paginationShow: false, //分页是否显示
    invokeiIterface: true, //是否调用接口
    rowMultiSelectWithClick: true, //点击行是否多选
    column: tableColumns1,
  })
  let refgridOption = ref<any>()
  let configaggrid = ref({
    url: 'wms/oldfornew/getPage', //接口路径
    queryData: {
      materialName: '',
      materialCode: '',
      firmId: '',
      warehouseId: '',
    },
    paginationShow: true, //分页是否显示
    invokeiIterface: true, //是否调用接口
    rowMultiSelectWithClick: true, //点击行是否多选
    column: tableColumns,
    fileName: 'OrderDeliveryList2-3',
    bottomTotal: true, //开启底部汇总
    bottomTotalConfig: ['totalNum'], //底部汇总列配置
  })
  let query = reactive<any>({
    materialCode: '',
    materialName: '',
    // companyId: '',
    firmId: '',
    warehouseId: '',
  })
  const fySelet: any = reactive({
    total: 10,
    size: 10,
    page: 1,
  })

  const PageSize = (val: any) => {
    fySelet.page = val
    cxCgsList()
  }

  const change = (val: any) => {
    fySelet.size = val
    cxCgsList()
  }

  const fySelet2: any = reactive({
    total: 10,
    size: 10,
    page: 1,
  })

  const PageSize2 = (val: any) => {
    fySelet2.page = val
    cxYcList()
  }

  const change2 = (val: any) => {
    fySelet2.size = val
    cxYcList()
  }

  const fySelet3: any = reactive({
    total: 10,
    size: 10,
    page: 1,
  })

  const PageSize3 = (val: any) => {
    fySelet3.page = val
    cxYcList2()
  }

  const change3 = (val: any) => {
    fySelet3.size = val
    cxYcList2()
  }

  const fySelet4: any = reactive({
    total: 10,
    size: 10,
    page: 1,
  })

  const PageSize4 = (val: any) => {
    fySelet4.page = val
    cxCgsLists()
  }

  const change4 = (val: any) => {
    fySelet4.size = val
    cxCgsLists()
  }

  const headerShow = ref(true)

  const tableDataList = ref([])

  const tableDataList2 = ref([])

  const tableDataList3 = ref([])

  const gridOption = ref()
  const colState = ref()
  const gridReady = (params: any) => {
    gridOption.value = params.api
    colState.value = params.columnApi
  }

  const gridOption2 = ref()
  const colState2 = ref()
  const gridReady2 = (params: any) => {
    gridOption2.value = params.api
    colState2.value = params.columnApi
  }
  const gridOptionwj = ref()
  const colStatewj = ref()
  const gridtableReadywj = (params: any) => {
    gridOptionwj.value = params.api
    colStatewj.value = params.columnApi
  }
  const gridOption3 = ref()
  const gridReady3 = (params: any) => {
    gridOption3.value = params.api
  }

  const defaultColDef = {
    sortable: true,
    resizable: true,
    filter: true,
  }

  const defaultColDef2 = {
    sortable: true,
    resizable: true,
    filter: true,
  }

  const localeText1: any = ref(localeText)

  const tc = [
    {
      showRowGroup: 'hide_def',
      headerName: '',
      checkboxSelection: true,
      headerCheckboxSelection: true,
      pinned: 'left',
      width: 50,
      resizable: false,
      filter: false,
      sortable: false,
      minWidth: 50,
      maxWidth: 50,
      lockPosition: 'left',
    },
    {
      headerName: '单号',
      field: 'orderNo',
      // pinned: o['fixed'],
      width: 150,
    },
    {
      headerName: '类型',
      field: 'infoType',
      width: 150,
      cellRenderer: {
        template: `<span>{{states==1?'领料出库':states==2?'调拨出库':states==3?'采购退货':states==4?'采购换货':states==6?'固定资产出库':'数据有误'}}</span>`,
        setup(props: any) {
          return {
            states: props.params.data.infoType,
          }
        },
      },
      cellStyle: (params: any) => {
        if (params.node.rowPinned == 'bottom') return { display: 'none' }
      },
      filterParams: {
        valueFormatter: function (params: any) {
          return params.value == '1'
            ? '领料出库'
            : params.value == '2'
            ? '调拨出库'
            : params.value == '3'
            ? '采购退货'
            : params.value == '4'
            ? '采购换货'
            : params.value == '6'
            ? '固定资产出库'
            : '数据有误'
        },
      },
    },
    {
      headerName: '出库类型',
      field: 'outStockType',
      width: 150,
    },
    {
      headerName: '公司',
      field: 'companyName',
      width: 150,
    },
    {
      headerName: '仓库类别',
      field: 'warehouseTypeName',
      width: 150,
    },
    {
      headerName: '仓库',
      field: 'warehouseName',
      width: 150,
    },
    {
      headerName: '五金领料单号',
      field: 'materialRequestNo',
      width: 150,
    },
    {
      headerName: '收货仓库类型',
      field: 'inWarehouseTypeName',
      width: 150,
    },
    {
      headerName: '收货公司',
      field: 'inCompanyName',
      width: 150,
    },
    {
      headerName: '收货仓库',
      field: 'inWarehouseName',
      width: 150,
    },
    {
      headerName: '物料大类',
      field: 'majorCategory',
      width: 150,
    },
    {
      headerName: '物料中类',
      field: 'middleCategory',
      width: 150,
    },
    {
      headerName: '物料小类',
      field: 'subCategory',
      width: 150,
    },
    {
      headerName: '物料编号',
      field: 'materialCode',
      width: 150,
    },
    {
      headerName: '物料名称',
      field: 'materialName',
      width: 150,
    },
    {
      headerName: '规格',
      field: 'specification',
      width: 150,
    },
    {
      headerName: '等级',
      field: 'grade',
      width: 150,
    },
    {
      headerName: '单价',
      field: 'price',
      width: 150,
    },
    {
      headerName: '出库数量',
      field: 'totalNum',
      width: 150,
    },
    {
      headerName: '单位',
      field: 'unit',
      width: 150,
    },
    {
      headerName: '品牌',
      field: 'brandName',
      width: 150,
    },
    {
      headerName: '设备编号',
      field: 'deviceCode',
      width: 150,
    },
    {
      headerName: '创建时间',
      field: 'createTime',
      width: 150,
    },
    {
      headerName: '状态',
      field: 'infoState',
      pinned: 'right',
      width: 190,
      cellRenderer: {
        template: `
            <a-button v-if="states == 2" status="success">已出库</a-button>
            <a-button v-if="states == 0"  status="warning">待审核</a-button>
            <a-space v-if="states == 1">
                <a-button type="primary" status="danger" disabled>已驳回</a-button>
                <a-button type="primary" @click="a">修改</a-button>    
            </a-space>
            <a-button v-if="states == 3"  >已完结</a-button>
            `,
        setup(props: any) {
          const a = () => {
            redersOut2(props.params.data)
          }
          return {
            a,
            states: props.params.data.infoState,
          }
        },
      },
      filterParams: {
        valueFormatter: function (params: any) {
          return params.value == '1'
            ? '已驳回'
            : params.value == '2'
            ? '已出库'
            : params.value == '3'
            ? '已完结'
            : params.value == '0'
            ? '待审核'
            : ''
        },
      },
    },
  ]

  const tc2 = [
    {
      showRowGroup: 'hide_def',
      headerName: '',
      checkboxSelection: true,
      headerCheckboxSelection: true,
      pinned: 'left',
      width: 50,
      resizable: false,
      filter: false,
      sortable: false,
      minWidth: 50,
      maxWidth: 50,
      lockPosition: 'left',
    },
    {
      headerName: '领料单号',
      field: 'pickCode',
      // pinned: o['fixed'],
      width: 150,
    },
    {
      headerName: '公司',
      field: 'companyName',
      // pinned: o['fixed'],
      width: 150,
    },
    {
      headerName: '部门',
      field: 'departmentName',
      width: 150,
    },
    {
      headerName: '仓库名称',
      field: 'warehouseName',
      width: 150,
    },
    {
      headerName: '领料时间',
      field: 'pickDate',
      width: 150,
    },
    {
      headerName: '物料大类',
      field: 'bigClassName',
      width: 150,
    },
    {
      headerName: '物料中类',
      field: 'middleClassName',
      width: 150,
    },
    {
      headerName: '物料小类',
      field: 'subClassName',
      width: 150,
    },
    {
      headerName: '物料编号',
      field: 'materialCode',
      width: 150,
    },
    {
      headerName: '物料名称',
      field: 'materialName',
      width: 150,
    },
    {
      headerName: '单位',
      field: 'unit',
      width: 150,
    },
    {
      headerName: '等级',
      field: 'grade',
      width: 150,
    },
    {
      headerName: '以旧换新',
      field: 'oldNewService',
      cellRenderer: {
        template: `
        <a-checkbox v-if="!isTotal" v-model="val" disabled></a-checkbox>
        <div v-else></div>
        `,
        setup(props: any) {
          let val = ref()
          val.value = props.params.data.oldNewService == 0 ? false : true
          const isTotal = ref(props.params.node.rowPinned == 'bottom')
          return {
            val,
            isTotal,
          }
        },
      },
      filterParams: {
        valueFormatter: function (params: any) {
          return params.value == '1' ? '已选' : '未选'
        },
      },
      width: 120,
    },
    {
      headerName: '以旧换新数量',
      field: 'oldNewNum',
      width: 150,
    },
    {
      headerName: '需求出库数量',
      field: 'num',
      width: 150,
    },
    {
      headerName: '库存数量',
      field: 'stockNum',
      width: 150,
    },
    {
      headerName: '需求时间',
      field: 'pickDate',
      width: 150,
    },
    {
      headerName: '设备编号',
      field: 'deviceCode',
      width: 150,
    },
    {
      headerName: '规格',
      field: 'materialSpec',
      width: 150,
    },
    {
      headerName: '单价',
      field: 'price',
      width: 150,
    },
    {
      headerName: '是否固定资产',
      field: 'fixAssetStatus',
      width: 150,
      cellRenderer: {
        template: `<a-checkbox v-model="val" disabled></a-checkbox>`,
        setup(props: any) {
          let val = ref()
          val.value =
            props.params.data.fixAssetStatus == null
              ? false
              : props.params.data.fixAssetStatus == 1
              ? true
              : false
          return {
            val,
          }
        },
      },
      cellStyle: (params) => {
        if (params.node.rowPinned == 'bottom') return { display: 'none' }
      },
    },
  ]

  const tc3 = [
    {
      showRowGroup: 'hide_def',
      headerName: '',
      checkboxSelection: true,
      headerCheckboxSelection: true,
      pinned: 'left',
      width: 50,
      resizable: false,
      filter: false,
      sortable: false,
      minWidth: 50,
      maxWidth: 50,
      lockPosition: 'left',
    },
    {
      headerName: '单号',
      field: 'orderNo',
      // pinned: o['fixed'],
      width: 150,
    },
    {
      headerName: '采购单号',
      field: 'purchaseOrderNo',
      // pinned: o['fixed'],
      width: 150,
    },
    {
      headerName: '供应商',
      field: 'supplierName',
      // pinned: o['fixed'],
      width: 150,
    },
    {
      headerName: '物料大类',
      field: 'majorCategory',
      width: 150,
    },
    {
      headerName: '物料中类',
      field: 'middleCategory',
      width: 150,
    },
    {
      headerName: '物料小类',
      field: 'subCategory',
      width: 150,
    },
    {
      headerName: '物料编号',
      field: 'materialCode',
      width: 150,
    },
    {
      headerName: '物料名称',
      field: 'materialName',
      width: 150,
    },
    {
      headerName: '规格',
      field: 'specification',
      width: 150,
    },
    {
      headerName: '单价',
      field: 'price',
      width: 150,
    },
    {
      headerName: '单位',
      field: 'unit',
      width: 150,
    },
    {
      headerName: '总数',
      field: 'totalNum',
      width: 150,
    },
    {
      headerName: '等级',
      field: 'grade',
      width: 150,
    },
    // {
    //     headerName: '库存数量',
    //     field: 'stockNum',
    //     width: 150
    // },
    {
      headerName: '状态',
      field: 'infoState',
      pinned: 'right',
      width: 190,
      cellRenderer: {
        template: `
            <a-button v-if="states == 2" status="success">已出库</a-button>
            <a-button v-if="states == 0"  status="warning">待审核</a-button>
            <a-button v-if="states == 3"  >已完结</a-button>
            `,
        setup(props: any) {
          const a = () => {
            redersOut2(props.params.data)
          }
          return {
            a,
            states: props.params.data.infoState,
          }
        },
      },
      filterParams: {
        valueFormatter: function (params: any) {
          return params.value == '2'
            ? '已出库'
            : params.value == '3'
            ? '已完结'
            : params.value == '0'
            ? '待审核'
            : ''
        },
      },
    },
  ]

  const selectHandler = () => {
    if (tabsKeys.value == 1) {
      cxYcList()
    } else if (tabsKeys.value == 2) {
      cxCgsList()
    } else if (tabsKeys.value == 3) {
      cxYcList2()
    } else if (tabsKeys.value == 4) {
      refgridOption.value.setQuery(query)
    }
  }
  onMounted(() => {
    updateGridState01()
    updateGridState02()
    cxYcList()
  })
  const tabsKeys = ref(1)

  const tabsChanges = (e: any) => {
    tabsKeys.value = e
    pageData.f = null
    if (e == 1) {
      cxYcList()
      toolbarList.value = [
        `${permissionStore.hasPermisson('yjcck.yclcx') ? '查询' : ''}`,
        `${permissionStore.hasPermisson('yjcck.xzdbd') ? '新建调拨单' : ''}`,
        `${permissionStore.hasPermisson('yjcck.yclsh') ? '审核' : ''}`,
        `${permissionStore.hasPermisson('yjcck.yclsc') ? '删除' : ''}`,
      ]
    } else if (e == 2) {
      cxCgsList()
      toolbarList.value = [
        `${permissionStore.hasPermisson('yjcck.llddclcx') ? '查询' : ''}`,
        `${permissionStore.hasPermisson('yjcck.llddclck') ? '出库' : ''}`,
      ]
    } else if (e == 3) {
      cxYcList2()
      toolbarList.value = [
        `${permissionStore.hasPermisson('yjcck.cgthcx') ? '查询' : ''}`,
        `${permissionStore.hasPermisson('yjcck.cgthxz') ? '新增' : ''}`,
        `${permissionStore.hasPermisson('yjcck.cgthsh') ? '审核' : ''}`,
        `${permissionStore.hasPermisson('yjcck.cgthsc') ? '删除' : ''}`,
      ]
    } else if (e == 4) {
      nextTick(() => {
        refgridOption.value.setQuery(query)
      })
      toolbarList.value = [`${permissionStore.hasPermisson('yjcck.cgthcx') ? '查询' : ''}`]
    }
  }

  const cgDcuList = reactive({
    pwDds: '',
    pwDds2: '',
  })

  const cxCgsList = async () => {
    // isWlNameds,
    // isWlCodeds,
    post({
      url: 'wms/ironwareOutStock/getIronwarePick',
      data: {
        page: fySelet.page,
        size: fySelet.size,
        pickCode: pageData.c,
        materialCode: pageData.d,
        materialName: pageData.e,
      },
    }).then((res: any) => {
      gridOption2.value.setRowData(res.data.list)
      setTableTotalRow(gridOption2, res.data.list, ['oldNewNum', 'num', 'stockNum'])
      tableDataList2.value = res.data.list
      fySelet.total = res.data.total
    })
  }

  const cxYcList = () => {
    if (pageData.dropDownTime.length == 0) {
      var beginTime = ''
      var endTime = ''
    } else {
      var beginTime = pageData.dropDownTime[0]
      var endTime = pageData.dropDownTime[1]
    }
    post({
      url: 'wms/ironwareOutStock/getPage',
      data: {
        page: fySelet2.page,
        size: fySelet2.size,
        companyId: pageData.a == '' ? null : pageData.a,
        warehouseId: pageData.b,
        orderNo: pageData.z,
        infoType: pageData.f == '' ? null : pageData.f,
        beginTime: compareDate(beginTime, endTime) == true ? endTime : beginTime,
        endTime: compareDate(beginTime, endTime) == true ? beginTime : endTime,
      },
    }).then((res: any) => {
      gridOption.value.setRowData(res.data.data)
      setTableTotalRow(gridOption, res.data.data, ['totalNum'])
      tableDataList.value = res.data.data
      fySelet2.total = res.data.total
    })
  }

  const cgRoutList: any = ref([])

  const redersOut = (record: any) => {
    if (gridOption2.value.getSelectedRows().length == 0) {
      Message.error('请选择领料单号')
      return
    }
    for (let i = 0; i < gridOption2.value.getSelectedRows().length; i++) {
      for (let j = i + 1; j < gridOption2.value.getSelectedRows().length; j++) {
        if (
          gridOption2.value.getSelectedRows()[i].materialRequestNo !=
          gridOption2.value.getSelectedRows()[j].materialRequestNo
        ) {
          Message.error('请勾选相同领料单号')
          return
        }
      }
    }
    for (let i = 0; i < gridOption2.value.getSelectedRows().length; i++) {
      if (gridOption2.value.getSelectedRows()[i].oldNewService == 1) {
        Message.warning(
          `物料名为 ${
            gridOption2.value.getSelectedRows()[i].materialName
          } 的单据以旧换新，旧物品退回换新物品!`
        )
      }
    }
    cgData.value = JSON.parse(JSON.stringify(gridOption2.value.getSelectedRows()))
    cgOut.visible = true
  }

  const cgOut = reactive({
    visible: false,
    visible2: false,
    title: '领料单出库',
  })

  const cgHandleOk = async (done: any) => {
    let shouldSkip = {
      state: false,
      materialCode: '',
    }
    cgData.value.some((item: any) => {
      if (item.fixAssetStatus === 1) {
        if ((item.num > 0 && !item.stockInfo) || item.num !== item.stockInfo.length) {
          shouldSkip.state = true
          shouldSkip.materialCode = item.materialCode
          return
        }
      }
    })

    if (shouldSkip.state) {
      console.log('跳出循环并提示')
      Message.warning(`请选择物料编码为${shouldSkip.materialCode}物料`)
      done(false)
    } else {
      cgData.value.forEach((item: any) => {
        item['companyId'] = item.companyId
        item['companyName'] = item.companyName
        item['infoType'] = 1
        item['outStockType'] = '领料出库'
        // delete item.firmId
        // delete item.firm
      })
      // console.log(cgData.value)
      const { code, message } = await post({
        url: 'wms/ironwareOutStock/addOut',
        data: cgData.value,
      })
      if (code == 200) {
        cxYcList()
        cxCgsList()
        Message.success('成功')
        return true
      }
      Message.error(message)
      return false
      done(true)
    }
  }

  const cgColumns: any = [
    {
      headerName: '领料单号',
      field: 'pickCode',
      // pinned: o['fixed'],
      width: 150,
    },
    {
      headerName: '公司',
      field: 'companyName',
      // pinned: o['fixed'],
      width: 150,
    },
    {
      headerName: '部门',
      field: 'departmentName',
      width: 150,
    },
    {
      headerName: '仓库名称',
      field: 'warehouseName',
      width: 150,
    },
    {
      headerName: '领料时间',
      field: 'pickDate',
      width: 150,
    },
    {
      headerName: '物料大类',
      field: 'bigClassName',
      width: 150,
    },
    {
      headerName: '物料中类',
      field: 'middleClassName',
      width: 150,
    },
    {
      headerName: '物料小类',
      field: 'subClassName',
      width: 150,
    },
    {
      headerName: '物料编号',
      field: 'materialCode',
      width: 150,
    },
    {
      headerName: '物料名称',
      field: 'materialName',
      width: 150,
    },
    {
      headerName: '单位',
      field: 'unit',
      width: 150,
    },
    {
      headerName: '等级',
      field: 'grade',
      width: 150,
    },
    {
      headerName: '以旧换新',
      field: 'oldNewService',
      cellRenderer: {
        template: `<a-checkbox v-model="val" disabled></a-checkbox>`,
        setup(props: any) {
          let val = ref()
          val.value = props.params.data.oldNewService == 0 ? false : true
          return {
            val,
          }
        },
      },
      filterParams: {
        valueFormatter: function (params: any) {
          return params.value == '1' ? '已选' : '未选'
        },
      },
      width: 120,
    },
    {
      headerName: '以旧换新数量',
      field: 'oldNewNum',
      width: 150,
    },
    {
      headerName: '需求出库数量',
      field: 'num',
      width: 150,
    },
    {
      headerName: '库存数量',
      field: 'stockNum',
      width: 150,
    },
    {
      headerName: '需求时间',
      field: 'pickDate',
      width: 150,
    },
    {
      headerName: '设备编号',
      field: 'deviceCode',
      width: 150,
    },
    {
      headerName: '规格',
      field: 'materialSpec',
      width: 150,
    },
    {
      headerName: '单价',
      field: 'price',
      width: 150,
    },
    {
      headerName: '是否固定资产',
      field: 'fixAssetStatus',
      width: 150,
      cellRenderer: {
        template: `<a-checkbox v-model="val" disabled></a-checkbox>`,
        setup(props: any) {
          let val = ref()
          val.value =
            props.params.data.fixAssetStatus == null
              ? false
              : props.params.data.fixAssetStatus == 1
              ? true
              : false
          return {
            val,
          }
        },
      },
    },
    {
      dataIndex: 'fixAssetStatus',
      field: 'fixAssetStatus',
      slotName: 'fixAssetStatus',
      headerName: '选择编号',
      width: 150,
      fixed: 'right',
      cellRenderer: {
        template: `
      <el-button v-if="record.fixAssetStatus == 1" @click="clickEvent(record)" linktitl
        style="color: #165dff">选择编号</el-button>
         `,
        setup(props: any) {
          const record = ref()
          record.value = props.params.data
          const clickEvent = (record) => {
            console.log(record)
            CheckNumber(record)
          }
          return {
            record,
            clickEvent,
          }
        },
      },
    },
  ]

  const warehouseChange = ($event: any, record: any) => {
    if ($event != '' || $event != undefined) {
      record['warehouseId'] = Number($event.split('-')[0])
      record['warehouseName'] = $event.split('-')[1]
      return
    }
  }

  const cadelvs = () => {
    cgData.value = []
    cgOut.visible = false
  }

  const delSles = () => {
    if (tabsKeys.value == 1) {
      if (tableDataList.value.length == 0) {
        Message.error('请勾选数据')
        return false
      }
      Modal.confirm({
        title: '系统提示',
        content: '确认删除选中的数据?',
        onOk: () => {
          post({
            url: 'wms/ironwareOutStock/delete',
            data: gridOption.value.getSelectedRows().map((res: any) => res.id),
          }).then((res: any) => {
            if (res.code == 200) {
              Message.success('删除成功')
              cxYcList()
            } else Message.error(res.message)
          })
        },
      })
    } else if (tabsKeys.value == 3) {
      if (tableDataList3.value.length == 0) {
        Message.error('请勾选数据')
        return false
      }
      Modal.confirm({
        title: '系统提示',
        content: '确认删除选中的数据?',
        onOk: () => {
          post({
            url: 'wms/ironwareOutStock/delete',
            data: gridOption3.value.getSelectedRows().map((res: any) => res.id),
          }).then((res: any) => {
            if (res.code == 200) {
              Message.success('删除成功')
              cxYcList2()
            } else Message.error(res.message)
          })
        },
      })
    }
  }

  const audits = () => {
    if (tabsKeys.value == 1) {
      if (tableDataList.value.length == 0) {
        Message.error('请勾选数据')
        return false
      }
      Modal.confirm({
        title: '系统提示',
        content: '确认是否审核选中的数据?',
        onOk: () => {
          post({
            url: 'wms/ironwareOutStock/audit',
            data: {
              infoState: 2,
              infos: gridOption.value.getSelectedRows().map((res: any) => {
                return { id: res.id }
              }),
            },
          }).then((res: any) => {
            if (res.code == 200) {
              Message.success('成功')
              cxYcList()
            } else Message.error(res.message)
          })
        },
      })
    } else if (tabsKeys.value == 3) {
      if (tableDataList3.value.length == 0) {
        Message.error('请勾选数据')
        return false
      }
      Modal.confirm({
        title: '系统提示',
        content: '确认是否审核选中的数据?',
        onOk: () => {
          post({
            url: 'wms/ironwareOutStock/audit',
            data: {
              infoState: 2,
              infos: gridOption3.value.getSelectedRows().map((res: any) => {
                return { id: res.id }
              }),
            },
          }).then((res: any) => {
            if (res.code == 200) {
              Message.success('成功')
              cxYcList2()
            } else Message.error(res.message)
          })
        },
      })
    }
  }

  const cgData: any = ref([])

  const adddbs = () => {
    dbPageDate.showAdd = true
  }

  const dbPageDate = reactive({
    showAdd: false,
    showAdd2: false,
    titles: '新建调拨单',
  })

  const formRef = ref()

  const sideOk = async () => {
    if (wlListArray.value.length == 0) {
      Message.warning({
        content: '请新增至少一条物料信息',
        duration: 5000,
      })
      return
    }
    for (let i = 0; i < wlListArray.value.length; i++) {
      if (wlListArray.value[i].totalNum == 0) {
        Message.error('数量必须大于0')
        return
      }
      // if (wlListArray.value[i].grade == '' || wlListArray.value[i].grade == null || wlListArray.value[i].grade == undefined) {
      //     Message.error('等级必填')
      //     return
      // }
    }

    formRef.value?.validate().then((err: any) => {
      if (!err) {
        wlListArray.value.forEach((item: any) => {
          item['companyId'] = searchData.fhFirmId
          item['companyName'] = searchData.fhFirm
          item['inCompanyId'] = searchData.shFirmId
          item['inCompanyName'] = searchData.shFirm
          item['inWarehouseTypeName'] = searchData.shWhType
          item['warehouseId'] = Number(searchData.fhWh.split('-')[0])
          item['warehouseName'] = searchData.fhWh.split('-')[1]
          item['inWarehouseId'] = Number(searchData.shWh.split('-')[0])
          item['inWarehouseName'] = searchData.shWh.split('-')[1]
          item['infoType'] = 2
          item['outStockType'] = '调拨单出库'
          item['warehouseTypeName'] = '五金仓'
          delete item.id
        })
        post({
          url: 'wms/ironwareOutStock/addOut',
          data: wlListArray.value,
        }).then(({ code, message }) => {
          if (code == 200) {
            cxYcList()
            cxCgsList()
            Message.success('成功')
            for (let i in searchData) {
              searchData[i] = ''
            }
            wlListArray.value = []
            dbPageDate.showAdd = false
          } else {
            Message.error(message)
          }
        })
      }
    })
  }

  const sideNo = () => {
    for (let i in searchData) {
      searchData[i] = ''
    }
    wlListArray.value = []
    dbPageDate.showAdd = false
  }

  const searchData: any = reactive({
    fhFirm: '',
    fhFirmId: null,
    fhWh: '',
    shFirm: '',
    shFirmId: null,
    shWhType: '',
    shWh: '',
    infoType: null,
  })

  const configCascader = ref<{}>({
    corporateWidth: '15rem', //公司宽度
    sectorWidth: '180px', //部门宽度
    corporateRquired: true, //公司是否必填
    sectorRquired: false, //部门是否必填
    size: 'mini', //选择框大小'mini' | 'small' | 'medium' | 'large'
    corporateName: '发货公司', //公司label
    sectorName: '选择部门', //部门label
    cascaderShow: 'sector', //配置部门不显示
  })
  const configCascader2 = ref<{}>({
    corporateWidth: '15rem', //公司宽度
    sectorWidth: '180px', //部门宽度
    corporateRquired: true, //公司是否必填
    sectorRquired: false, //部门是否必填
    size: 'mini', //选择框大小'mini' | 'small' | 'medium' | 'large'
    corporateName: '收货公司', //公司label
    sectorName: '选择部门', //部门label
    cascaderShow: 'sector', //配置部门不显示
  })
  const whService = new WHService()
  const fhWhList: any = whService.whList
  const changeCascader = (data: any) => {
    const { corporateId, sectorId, sectorLabel, corporateLabel } = data
    searchData.fhWh = ''
    searchData.fhFirmId = corporateId
    searchData.fhFirm = corporateLabel
    whService.getWarhouseListByFirmId(corporateId, '五金仓')
  }
  const changeCascader2 = (data: any) => {
    const { corporateId, sectorId, sectorLabel, corporateLabel } = data
    searchData.shWh = ''
    searchData.shFirmId = corporateId
    searchData.shFirm = corporateLabel
    whService.getWarhouseListByFirmId(corporateId, '五金仓')
  }
  const whTypeList: any = ref([])

  const whService2 = new WHService()
  const shWhList: any = whService2.whList
  const whTypeChanges = (e: any) => {
    whService2.getWarhouseListByFirmId(searchData.shFirmId, e)
  }

  const wlListArray: any = ref([])

  const tableColumnsWl: any = [
    {
      headerName: '物料大类',
      field: 'majorCategory',
      dataIndex: 'majorCategory',
      width: 150,
      slotName: 'majorCategory',
    },
    {
      headerName: '物料中类',
      field: 'middleCategory',
      dataIndex: 'middleCategory',
      width: 150,
      slotName: 'middleCategory',
    },
    {
      headerName: '物料小类',
      field: 'subCategory',
      dataIndex: 'subCategory',
      width: 150,
      slotName: 'subCategory',
    },
    {
      headerName: '物料编号',
      field: 'materialCode',
      dataIndex: 'materialCode',
      width: 150,
      slotName: 'materialCode',
    },
    {
      headerName: '物料名称',
      field: 'materialName',
      dataIndex: 'materialName',
      width: 150,
      slotName: 'materialName',
    },
    {
      dataIndex: 'newGrade',
      field: 'newGrade',
      headerName: '等级',
      width: 150,
      slotName: 'newGrade',
    },
    {
      headerName: '单位',
      field: 'unit',
      dataIndex: 'unit',
      width: 150,
    },
    {
      dataIndex: 'specification',
      field: 'specification',
      headerName: '规格',
      width: 150,
    },
    {
      dataIndex: 'price',
      field: 'price',
      headerName: '单价',
      width: 150,
    },
    {
      headerName: '出库数量',
      field: 'totalNum',
      dataIndex: 'totalNum',
      width: 150,
      slotName: 'totalNum',
      cellRenderer: {
        template: `
            <a-input-number v-model="record.totalNum" class="input-demo bacClass" :min="0" :max="record.totalNum2"
                  :precision="2" />
         `,
        setup(props: any) {
          const record = ref()
          record.value = props.params.data
          return {
            record,
          }
        },
      },
    },
    {
      dataIndex: 'totalNum2',
      field: 'totalNum2',
      slotName: 'totalNum2',
      headerName: '库存数量',
      width: 150,
    },
  ]
  let typeIds = 0
  const wjModalLayout = ref()
  const addLine = () => {
    if (searchData.fhWh == '' || searchData.fhFirm == '' || searchData.shWhType == '') {
      Message.error('请先选择发货公司仓库收货仓库类型')
      return
    }
    xuanZeCaigou.value = '选择五金库存'
    visibleYl.value = true
    wjModalLayout.value.reCountHeight()
    // wlListArray.value.push({
    //     typeIds: typeIds++,
    //     majorCategory: '',
    //     subCategory: '',
    //     materialCode: '',
    //     unit: '',
    //     materialName: '',
    //     totalNum: 0
    // })
  }

  const selectedRowKeysWl: any = ref([])

  const delLine = () => {
    if (selectedRowKeysWl.value.length === 0) {
      Message.error({
        content: '请先勾选',
        duration: 5000,
      })
      return
    }

    wlListArray.value = wlListArray.value.filter(function (o: any) {
      return selectedRowKeysWl.value.indexOf(o['typeIds']) === -1
    })
  }

  const wlPageDatas: any = reactive({
    wlListL: [],
    wlListS: [],
    wlList: [],
  })

  const focusSel = () => {
    post({
      url: 'purchase/MaterialBigClass/getFieldValue',
      data: { bigClassName: '', deleteState: 0 },
    }).then(({ data, code }: any) => {
      if (code === 200) {
        wlPageDatas.wlListL = data
      } else {
        Message.error({
          content: '查询失败！',
          duration: 5000,
        })
      }
    })
  }
  const focusSel1 = (e: any) => {
    if (e.majorCategory == '') {
      Message.error('请先选择物料大类')
      return
    }
    post({
      url: 'purchase/MaterialSubClass/getFieldValue',
      data: { bigClassName: e.majorCategory },
    }).then(({ data, code }: any) => {
      if (code === 200) {
        wlPageDatas.wlListS = data
      } else {
        Message.error({
          content: '查询失败！',
          duration: 5000,
        })
      }
    })
  }
  const focusSel2 = (val: any) => {
    post({
      url: 'purchase/MaterialInfo/getFieldValueWms',
      data: val,
    }).then(({ data, code }: any) => {
      if (code === 200) {
        wlPageDatas.wlList = data
      } else {
        Message.error({
          content: '查询失败！',
          duration: 5000,
        })
      }
    })
  }

  const cxKcsl = async (val: any, val2: any) => {
    const res = await post({
      url: 'wms/ironwareStockSummary/getGoodsStockNum',
      data: {
        materialCode: val,
        grade: val2,
        warehouseId: Number(searchData.fhWh.split('-')[0]),
      },
    })
    if (res.code == 200) {
      return res.data.totalNum
    }
  }

  const changeWl = (record: any, val: any) => {
    if (val == '') {
      record['materialName'] = ''
      record['materialCode'] = ''
      record['specification'] = ''
      record['majorCategory'] = ''
      record['subCategory'] = ''
      record['unit'] = ''
      return
    }
    let list2 = wlListArray.value.filter(function (o: any) {
      return o['materialName'] == record['materialName']
    })
    if (list2.length > 1) {
      record['materialName'] = ''
      record['materialCode'] = ''
      record['specification'] = ''
      record['majorCategory'] = ''
      record['subCategory'] = ''
      record['unit'] = ''
      Message.warning({
        content: '请不要重复选择物料！',
        duration: 5000,
      })
      return
    }
    let list = wlPageDatas.wlList.filter(function (o: any) {
      return o['materialName'] == val
    })
    if (list.length > 0) {
      record['materialCode'] = list[0]['materialCode']
      record['unit'] = list[0]['unit']
      record['specification'] = list[0]['specification']
      record['majorCategory'] = list[0]['materialL']
      record['subCategory'] = list[0]['materialS']
      cxKcsl(val, record['grade']).then((res: any) => {
        record['totalNum2'] = res
      })
    }
  }
  const changeWl2 = (record: any, val: any) => {
    if (val == '') {
      record['materialName'] = ''
      record['materialCode'] = ''
      record['specification'] = ''
      record['majorCategory'] = ''
      record['subCategory'] = ''
      record['unit'] = ''
      return
    }
    let list2 = wlListArray.value.filter(function (o: any) {
      return o['materialCode'] == record['materialCode']
    })
    if (list2.length > 1) {
      record['materialName'] = ''
      record['materialCode'] = ''
      record['unit'] = ''
      record['specification'] = ''
      record['majorCategory'] = ''
      record['subCategory'] = ''
      Message.warning({
        content: '请不要重复选择物料！',
        duration: 5000,
      })
      return
    }
    let list = wlPageDatas.wlList.filter(function (o: any) {
      return o['materialCode'] == val
    })
    if (list.length > 0) {
      record['materialName'] = list[0]['materialName']
      record['unit'] = list[0]['unit']
      record['specification'] = list[0]['specification']
      record['majorCategory'] = list[0]['materialL']
      record['subCategory'] = list[0]['materialS']
      cxKcsl(val, record['grade']).then((res: any) => {
        record['totalNum2'] = res
      })
    }
  }
  const qkChanges = (record: any) => {
    record['materialCode'] = ''
    record['unit'] = ''
    record['materialName'] = ''
  }

  const gradrList: any = ref([])

  const gradeChange = (e: any) => {
    if (e.materialName == '' || e.materialCode == '') {
      Message.error('请先选择物料')
      return
    }
    post({
      url: 'dict/dictTypeDetail/getListByMap',
      data: {
        codeType: 36,
        detailName: '',
      },
    }).then(({ data, code }: any) => {
      if (code === 200) {
        gradrList.value = data
      }
    })
  }

  const totalNum2: any = ref()

  const grachanges = (e: any) => {
    cxKcsl(e['materialCode'], e['grade']).then((res: any) => {
      e['totalNum2'] = res
    })
  }

  const configCascader3 = ref<{}>({
    corporateWidth: '180px', //公司宽度
    sectorWidth: '180px', //部门宽度
    corporateRquired: false, //公司是否必填
    sectorRquired: false, //部门是否必填
    size: 'small', //选择框大小'mini' | 'small' | 'medium' | 'large'
    corporateName: '选择公司', //公司label
    sectorName: '选择部门', //部门label
    cascaderShow: 'sector', //配置部门不显示
  })
  const whService3 = new WHService()
  const fhWhList3: any = whService3.whList
  const changeCascader3 = (data: any) => {
    const { corporateId, sectorId, sectorLabel, corporateLabel } = data
    pageData.b = ''
    pageData.a = corporateId
    whService3.getWarhouseListByFirmId(corporateId, '五金仓')
  }
  const configCascader4 = ref<{}>({
    corporateWidth: '180px', //公司宽度
    sectorWidth: '180px', //部门宽度
    corporateRquired: false, //公司是否必填
    sectorRquired: false, //部门是否必填
    size: 'small', //选择框大小'mini' | 'small' | 'medium' | 'large'
    corporateName: '选择公司', //公司label
    sectorName: '选择部门', //部门label
    cascaderShow: 'sector', //配置部门不显示
  })
  const fhWhList4 = ref<any>([])
  const changeCascader4 = (data: any) => {
    const { corporateId, sectorId, sectorLabel, corporateLabel } = data
    query.warehouseId = ''
    fhWhList4.value = []
    query.firmId = corporateId
    getByFirmId(corporateId)
  }
  const getByFirmId = async (id: string) => {
    try {
      let res: any = await post({
        url: 'wms/warehouse/getWarehouseByPara',
        data: {
          firmId: id,
          warehouseTypeName: '五金仓',
          virtuallyState: 0,
        },
      })
      if (res.code == 200) {
        fhWhList4.value = res.data
        return
      }
      ElMessage.error(res.message)
    } finally {
      pageData.loadingUp2 = false
    }
  }
  const cgHandleOk2 = async () => {
    const { code, message } = await post({
      url: 'wms/ironwareOutStock/updateById',
      data: cgData2.value[0],
    })
    if (code == 200) {
      cxYcList()
      cxCgsList()
      Message.success('成功')
      return true
    }
    Message.error(message)
    return false
  }

  const cadelvs2 = () => {
    cgData2.value = []
    cgOut.visible2 = false
  }

  const cgData2: any = ref([])

  const cgColumns2: any = [
    {
      dataIndex: 'orderNo',
      key: 'orderNo',
      title: '单号',
      width: 150,
    },
    {
      dataIndex: 'outStockType',
      key: 'outStockType',
      title: '出库类型',
      width: 150,
    },
    {
      dataIndex: 'companyName',
      key: 'companyName',
      title: '公司',
      width: 150,
    },
    {
      dataIndex: 'warehouseTypeName',
      key: 'warehouseTypeName',
      title: '仓库类别',
      width: 150,
    },
    {
      dataIndex: 'warehouseName',
      key: 'warehouseName',
      title: '仓库',
      width: 150,
    },
    {
      dataIndex: 'materialRequestNo',
      key: 'materialRequestNo',
      title: '五金领料单号',
      width: 150,
    },
    {
      dataIndex: 'inWarehouseTypeName',
      key: 'inWarehouseTypeName',
      title: '收货仓库类型',
      width: 150,
    },
    {
      dataIndex: 'inCompanyName',
      key: 'inCompanyName',
      title: '收货公司 ',
      width: 150,
    },
    {
      dataIndex: 'inWarehouseName',
      key: 'inWarehouseName',
      title: '收货仓库 ',
      width: 150,
    },
    {
      dataIndex: 'majorCategory',
      key: 'majorCategory',
      title: '物料大类',
      width: 150,
    },
    {
      dataIndex: 'middleCategory',
      key: 'middleCategory',
      title: '物料中类',
      width: 150,
    },
    {
      dataIndex: 'subCategory',
      key: 'subCategory',
      title: '物料小类',
      width: 150,
    },
    {
      dataIndex: 'materialCode',
      key: 'materialCode',
      title: '物料编号',
      width: 150,
    },
    {
      dataIndex: 'materialName',
      key: 'materialName',
      title: '物料名称',
      width: 150,
    },
    {
      dataIndex: 'specification',
      key: 'specification',
      title: '规格',
      width: 150,
    },
    {
      dataIndex: 'price',
      key: 'price',
      title: '单价',
      width: 150,
    },
    {
      headerName: '等级',
      field: 'grade',
      width: 150,
    },
    {
      dataIndex: 'unit',
      key: 'unit',
      title: '单位',
      width: 150,
    },
    {
      dataIndex: 'totalNum',
      key: 'totalNum',
      title: '出库数量',
      slotName: 'totalNum',
      width: 150,
      fixed: 'right',
    },
  ]

  const redersOut2 = (data: any) => {
    cgData2.value = JSON.parse(JSON.stringify([data]))
    cgOut.visible2 = true
  }

  const addList = () => {
    fhWhList.value = []
    cgData4.value = []
    searchData.infoType = null
    searchData.fhWh = ''
    pageData.g = ''
    dbPageDate.showAdd2 = true
  }

  const cgData3: any = ref([])

  const delLine2 = (e: any) => {
    Modal.confirm({
      title: '系统提示',
      content: '确认删除选中的数据?',
      onOk: () => {
        cgData4.value = cgData4.value.filter((val: any) => {
          return val != e
        })
      },
    })
  }
  const cxYcList2 = () => {
    post({
      url: 'wms/ironwareOutStock/getPagePur',
      data: {
        page: fySelet3.page,
        size: fySelet3.size,
        companyId: pageData.a == '' ? null : pageData.a,
        warehouseId: pageData.b,
        orderNo: pageData.z,
        infoType: pageData.f == '' ? 3 : pageData.f,
      },
    }).then((res: any) => {
      gridOption3.value.setRowData(res.data.data)
      tableDataList3.value = res.data.data
      fySelet3.total = res.data.total
    })
  }

  const formRef2 = ref()

  const sideOk2 = () => {
    if (cgData4.value.length == 0) {
      Message.error('请选择采购单')
      return
    }
    formRef2.value?.validate().then((err: any) => {
      if (!err) {
        cgData4.value.forEach((item: any) => {
          item['companyId'] = searchData.fhFirmId
          item['companyName'] = searchData.fhFirm
          item['warehouseId'] = Number(searchData.fhWh.split('-')[0])
          item['warehouseName'] = searchData.fhWh.split('-')[1]
          item['infoType'] = searchData.infoType
        })
        post({
          url: 'wms/ironwareOutStock/addOut',
          data: cgData4.value,
        }).then(({ code, message }) => {
          if (code == 200) {
            cxYcList2()
            Message.success('成功')
            for (let i in searchData) {
              searchData[i] = ''
            }
            cgData4.value = []
            dbPageDate.showAdd2 = false
          } else {
            Message.error(message)
          }
        })
      }
    })
  }
  const sideNo2 = () => {
    fhWhList.value = []
    cgData4.value = []
    searchData.infoType = null
    searchData.fhWh = ''
    pageData.g = ''
    dbPageDate.showAdd2 = false
  }

  const addLine2 = () => {
    if (searchData.fhWh == '' || searchData.fhWh == undefined) {
      Message.error('请先选择仓库')
      return
    }
    xuanZeCaigou.value = '选择采购单'
    visibleYl.value = true
    // wjModalLayout.value.reCountHeight()
  }
  const cgColumns4: any = [
    {
      headerName: '',
      checkboxSelection: true,
      headerCheckboxSelection: true,
      width: 50,
      maxWidth: 50,
      resizable: false,
    },
    {
      dataIndex: 'purchaseOrderNo',
      field: 'purchaseOrderNo',
      headerName: '采购单号',
      width: 150,
    },
    {
      dataIndex: 'supplierName',
      field: 'supplierName',
      headerName: '供应商名称',
      width: 150,
    },
    {
      dataIndex: 'majorCategory',
      field: 'majorCategory',
      headerName: '物料大类',
      width: 150,
    },
    {
      dataIndex: 'middleCategory',
      field: 'middleCategory',
      headerName: '物料中类',
      width: 150,
    },
    {
      dataIndex: 'subCategory',
      field: 'subCategory',
      headerName: '物料小类',
      width: 150,
    },
    {
      dataIndex: 'materialCode',
      field: 'materialCode',
      headerName: '物料编号',
      width: 150,
    },
    {
      dataIndex: 'materialName',
      field: 'materialName',
      headerName: '物料名称',
      width: 150,
    },
    {
      dataIndex: 'specification',
      field: 'specification',
      headerName: '规格',
      width: 150,
    },
    {
      dataIndex: 'price',
      field: 'price',
      headerName: '单价',
      width: 150,
    },
    {
      dataIndex: 'unit',
      field: 'unit',
      headerName: '单位 ',
      width: 150,
    },
    {
      dataIndex: 'grade',
      field: 'grade',
      headerName: '等级 ',
      width: 150,
    },
    {
      dataIndex: 'purchaseNum',
      field: 'purchaseNum',
      headerName: '采购数量',
      width: 150,
    },
    {
      dataIndex: 'inStockNum',
      field: 'inStockNum',
      headerName: '采购已入库数量',
      width: 150,
    },
    {
      dataIndex: 'stockNum',
      field: 'stockNum',
      headerName: '库存数量 ',
      width: 150,
    },
    {
      dataIndex: 'returnNum',
      field: 'returnNum',
      headerName: '已退货数量',
      slotName: 'returnNum',
      width: 150,
    },
    {
      dataIndex: 'totalNum',
      field: 'totalNum',
      headerName: '退货数量',
      slotName: 'totalNum',
      width: 150,
      fixed: 'right',
      cellRenderer: {
        template: `
      <a-input-number class="bacClass" v-model="record.totalNum" :max="record.inStockNum - record.returnNum"
            :min="0"></a-input-number>           
      `,
        setup(props: any) {
          const record = ref()
          record.value = props.params.data
          return {
            record,
          }
        },
      },
    },
    {
      dataIndex: 'returnNum',
      field: 'returnNum',
      headerName: '已退货数量',
      width: 150,
      fixed: 'right',
    },
    {
      dataIndex: 'acFighs',
      field: 'acFighs',
      headerName: '操作',
      slotName: 'acFighs',
      width: 150,
      fixed: 'right',
      cellRenderer: {
        template: `
      <a-button type="primary" @click="delLine2(record)" size="mini">删除</a-button>            
      `,
        setup(props: any) {
          const record = ref()
          record.value = props.params.data
          const clickEvent = (record: any) => {
            delLine2(record)
          }
          return {
            record,
            clickEvent,
          }
        },
      },
    },
  ]
  const cgData4: any = ref([])

  const visibleYl = ref(false)
  const materialCode: any = ref('')
  const materialName: any = ref('')
  const specName: any = ref('')
  const selectedRowKeys2: any = ref([])
  const wlListXqs: any = ref([])

  const handleOks = () => {
    selectedRowKeys2.value = gridOptionwj.value
      .getSelectedRows()
      .map((item: any) => item.typeLesIds)

    if (selectedRowKeys2.value.length == 0) {
      Message.error('请勾选数据')
      return false
    }
    //判断是否有相同的物料编号和等级
    if (wlListXqs.value.length > 0 && wlListArray.value.length > 0) {
      for (let i = 0; i < wlListArray.value.length; i++) {
        for (let j = 0; j < wlListXqs.value.length; j++) {
          if (
            wlListArray.value[i]['materialCode'] == wlListXqs.value[j]['materialCode'] &&
            wlListArray.value[i]['grade'] == wlListXqs.value[j]['grade']
          ) {
            Message.error('请勿勾选相同等级的物料')
            return
          }
        }
      }
    }

    let islistArray: any = []
    for (let i = 0; i < wlListXqs.value.length; i++) {
      if (selectedRowKeys2.value.includes(wlListXqs.value[i].typeLesIds)) {
        islistArray.push(wlListXqs.value[i])
      }
    }

    if (xuanZeCaigou.value == '选择采购单') {
      if (cgData4.value.length != 0) {
        let wlAarray: any = []
        for (let i = 0; i < islistArray.length; i++) {
          wlAarray.push(islistArray[i].materialCode)
        }
        for (let i = 0; i < cgData4.value.length; i++) {
          if (wlAarray.includes(cgData4.value[i].materialCode)) {
            Message.error('请勿勾选相同物料')
            return false
          }
        }
        for (let i = 0; i < islistArray.length; i++) {
          if (cgData4.value[0].purchaseOrderNo != islistArray[i].purchaseOrderNo) {
            Message.error('请勾选相同采购单')
            return false
          }
        }
      }
      islistArray.forEach((res: any) => {
        res['totalNum'] = 0
      })
      cgData4.value.push(...islistArray)
    } else if (xuanZeCaigou.value == '选择五金库存') {
      if (wlListArray.value.length != 0) {
        let wlAarray: any = []
        for (let i = 0; i < islistArray.length; i++) {
          wlAarray.push(islistArray[i].materialCode)
        }
        for (let i = 0; i < cgData4.value.length; i++) {
          if (wlAarray.includes(wlListArray.value[i].materialCode)) {
            Message.error('请勿勾选相同物料')
            return false
          }
        }
        for (let i = 0; i < selectedRowKeys2.value.length; i++) {
          if (selectedRowKeys2.value[i].fixAssetStatus == 1) {
            Message.warning(
              `物料名为 ${selectedRowKeys2.value[i].materialName} 的单据是固定资产，不能选择!`
            )
          }
        }
      }
      if (searchData.shWhType == '制具仓') {
        islistArray.forEach((res: any) => {
          ;(res['typeIds'] = typeIds++), (res['totalNum'] = 0)
          if (res['grade'] == null || res['grade'] == '' || res['grade'] == undefined) {
            res['newGrade'] = 'A'
          } else {
            res['newGrade'] = res['grade']
          }
        })
      } else {
        islistArray.forEach((res: any) => {
          ;(res['typeIds'] = typeIds++), (res['newGrade'] = res['grade'])
          res['totalNum'] = 0
        })
      }
      wlListArray.value.push(...islistArray)
      gridtableOptiondb.value.setRowData(wlListArray.value)
      console.log(wlListArray.value)
    }
    materialCode.value = ''
    materialName.value = ''
    objectOP.bigClassName1 = ''
    objectOP.bigClassName2 = ''
    objectOP.bigClassName3 = ''
    specName.value = ''
    wlListXqs.value = []
    selectedRowKeys2.value = []
    visibleYl.value = false
    return true
  }
  let typeLesIds = 0
  const xuanZeCaigou = ref('')
  const cxCgsLists = async () => {
    if (xuanZeCaigou.value == '选择采购单') {
      const res: any = await post({
        url: 'wms/ironwareInStock/getPageByInStockRecord',
        data: {
          page: fySelet4.page,
          size: fySelet4.size,
          warehouseId: Number(searchData.fhWh.split('-')[0]),
          materialCode: materialCode.value,
          materialName: materialName.value,
          majorCategory: objectOP.bigClassName1,
          subCategory: objectOP.bigClassName3,
          middleCategory: objectOP.bigClassName2,
          specName: specName.value,
        },
      })
      if (res.code == 200) {
        wlListXqs.value = res.data.list
        wlListXqs.value.forEach((res: any) => {
          res['typeLesIds'] = typeLesIds++
          res['totalNum2'] = res.totalNum
        })
        fySelet4.total = res.data.total
      }
    } else if (xuanZeCaigou.value == '选择五金库存') {
      // wms/ironwareStockSummary/getPage
      const res: any = await post({
        url: 'wms/ironwareStockSummary/getPage',
        data: {
          page: fySelet4.page,
          size: fySelet4.size,
          warehouseId: Number(searchData.fhWh.split('-')[0]),
          materialCode: materialCode.value,
          materialName: materialName.value,
          majorCategory: objectOP.bigClassName1,
          subCategory: objectOP.bigClassName3,
          middleCategory: objectOP.bigClassName2,
          specName: specName.value,
          fixAssetStatus: 0,
        },
      })
      if (res.code == 200) {
        wlListXqs.value = res.data.data
        wlListXqs.value.forEach((res: any) => {
          res['typeLesIds'] = typeLesIds++
          res['totalNum2'] = res.totalNum
        })
        fySelet4.total = res.data.total
      }
    }
  }
  const handleCancels = () => {
    materialCode.value = ''
    materialName.value = ''
    objectOP.bigClassName1 = ''
    objectOP.bigClassName2 = ''
    objectOP.bigClassName3 = ''
    specName.value = ''
    wlListXqs.value = []
    selectedRowKeys2.value = []
    visibleYl.value = false
  }

  const cgColumns5: any = [
    {
      showRowGroup: 'hide_def',
      headerName: '',
      checkboxSelection: true,
      headerCheckboxSelection: true,
      pinned: 'left',
      width: 50,
      resizable: false,
      filter: false,
      sortable: false,
      minWidth: 50,
      maxWidth: 50,
      lockPosition: 'left',
    },
    {
      dataIndex: 'majorCategory',
      field: 'majorCategory',
      headerName: '物料大类',
      width: 150,
    },
    {
      dataIndex: 'middleCategory',
      field: 'middleCategory',
      headerName: '物料中类',
      width: 150,
    },
    {
      dataIndex: 'subCategory',
      field: 'subCategory',
      headerName: '物料小类',
      width: 150,
    },
    {
      dataIndex: 'materialCode',
      field: 'materialCode',
      headerName: '物料编号',
      width: 150,
    },
    {
      dataIndex: 'materialName',
      field: 'materialName',
      headerName: '物料名称',
      width: 150,
    },
    {
      dataIndex: 'specification',
      field: 'specification',
      headerName: '规格',
      width: 150,
    },
    {
      dataIndex: 'price',
      field: 'price',
      headerName: '单价',
      width: 150,
    },
    {
      dataIndex: 'unit',
      field: 'unit',
      headerName: '单位 ',
      width: 150,
    },
    {
      dataIndex: 'grade',
      field: 'grade',
      headerName: '等级 ',
      width: 150,
    },
    {
      dataIndex: 'totalNum',
      field: 'totalNum',
      headerName: '库存数量 ',
      width: 150,
    },
    {
      dataIndex: 'fixAssetStatus',
      field: 'fixAssetStatus',
      slotName: 'fixAssetStatus',
      pinned: 'right',
      headerName: '是否固资',
      width: 150,
      cellRenderer: {
        template: `
      <el-checkbox v-model="record.fixAssetStatus" disabled :true-label="1" :false-label="0"></el-checkbox>
  
         `,
        setup(props: any) {
          const record = ref()
          record.value = props.params.data
          return {
            record,
          }
        },
      },
    },
    // {
    //     dataIndex: 'totalNum',
    //     key: 'totalNum',
    //     title: '已入库数量',
    //     slotName: 'totalNum',
    //     width: 150,
    // },
  ]
  const cgColumns6: any = [
    {
      dataIndex: 'purchaseOrderNo',
      key: 'purchaseOrderNo',
      title: '采购单号',
      width: 150,
    },
    {
      dataIndex: 'majorCategory',
      key: 'majorCategory',
      title: '物料大类',
      width: 150,
    },
    {
      dataIndex: 'middleCategory',
      key: 'middleCategory',
      title: '物料中类',
      width: 150,
    },
    {
      dataIndex: 'subCategory',
      key: 'subCategory',
      title: '物料小类',
      width: 150,
    },
    {
      dataIndex: 'materialCode',
      key: 'materialCode',
      title: '物料编号',
      width: 150,
    },
    {
      dataIndex: 'materialName',
      key: 'materialName',
      title: '物料名称',
      width: 150,
    },
    {
      dataIndex: 'specification',
      key: 'specification',
      title: '规格',
      width: 150,
    },
    {
      dataIndex: 'price',
      key: 'price',
      title: '单价',
      width: 150,
    },
    {
      dataIndex: 'unit',
      key: 'unit',
      title: '单位 ',
      width: 150,
    },
    {
      dataIndex: 'grade',
      key: 'grade',
      title: '等级 ',
      width: 150,
    },
    {
      dataIndex: 'stockNum',
      key: 'stockNum',
      title: '库存数量 ',
      width: 150,
    },
    {
      dataIndex: 'totalNum',
      key: 'totalNum',
      title: '已入库数量',
      slotName: 'totalNum',
      width: 150,
    },
  ]

  const corport: any = ref()
  const compareDate = (dateTime1: any, dateTime2: any) => {
    var formatDate1 = new Date(dateTime1)
    var formatDate2 = new Date(dateTime2)
    if (formatDate1 > formatDate2) {
      return true
    } else {
      return false
    }
  }
  const onSelect = (dateString: any, date: any) => {
    pageData.dropDownTime = {
      beginTime: dateString[0],
      endTime: dateString[1],
    }
  }
  const onClear = () => {
    pageData.dropDownTime = []
  }

  const printListPldy = ref<any>()
  const visiblecg = ref(false)
  const printOut = () => {
    if (gridOption.value.getSelectedRows().length == 0) {
      Message.error('请勾选数据')
      return false
    } else {
      let list = gridOption.value.getSelectedRows()
      let flag = false
      for (let i = 1; i < list.length; i++) {
        if (list[0]['orderNo'] != list[i]['orderNo']) {
          flag = true
        }
        if (flag) {
          Message.error({
            content: '勾选数据的单号不一致',
            duration: 5000,
          })
          return
        }
      }
      post({
        url: 'wms/ironwareOutStock/getPrintIronwareOutStock',
        data: { orderNo: list[0]['orderNo'] },
      }).then(({ code, data, message }: any) => {
        if (code === 200) {
          pageData.dataList = []
          visiblecg.value = true
          pageData.dataList.push(data)
          // console.log(pageData.dataList, '看看你是谁');

          // printListPldy = data
        }
      })
    }
  }
  const print1 = () => {
    printJS({
      printable: 'dyy2',
      type: 'html',
      targetStyles: ['*'],
      font_size: '',
    })
  }

  //打印预览PDF
  const printPdf = () => {
    if (gridOption.value.getSelectedRows().length == 0) {
      Message.error('请勾选数据')
      return false
    } else {
      var list: any = []
      for (let i = 0; i < gridOption.value.getSelectedRows().length; i++) {
        var ob = {}
        ob['orderNo'] = gridOption.value.getSelectedRows()[i].orderNo
        list.push(ob)
      }
      //去重
      const uniqueArr = Array.from(new Set(list.map((item) => item.orderNo))).map((orderNo) => {
        return list.find((item) => item.orderNo === orderNo)
      })
      post({
        url: 'wms/ironwareOutStock/getPrintIronwareOutStock',
        data: uniqueArr,
        responseType: 'blob',
      }).then((res) => {
        let reader = new FileReader()
        reader.readAsDataURL(res)
        reader.onload = function () {
          let pdfBase64 = reader.result.replace('data:application/pdf;base64,', '')
          printJS({ printable: pdfBase64, type: 'pdf', base64: true })
        }
      })
    }
  }

  const NumChange = (record: any) => {
    if (record.oldNewNum > record.totalNum) {
      record.oldNewNum == null
      Message.warning('不能超过出库数量!')
      return false
    }
  }

  const numEnter = (record: any) => {
    if (record.oldNewService == 0) {
      pageData.isEdit = true
    } else {
      pageData.isEdit = false
    }
  }
  const CheckNumber = (data: any) => {
    pageData.CheckNumberList = data
    configaggrid1.value.queryData.materialCode = data.materialCode
    configaggrid1.value.queryData.warehouseId = data.warehouseId
    console.log(configaggrid1.value.queryData)
    nextTick(() => {
      pageData.showAdd1 = true
      //   refgridOption1.value.setQuery({
      //     materialCode: data.materialCode,
      //     warehouseId: data.warehouseId,
      //   })
    })
  }
  const save1 = () => {
    let arr = refgridOption1.value.getSelectedRows()
    if (arr.length == 0) {
      ElMessage.warning('请勾选至少一条')
      return
    }
    if (arr.length != pageData.CheckNumberList.num) {
      ElMessage.warning(`请勾选${pageData.CheckNumberList.num}条数据`)
      return
    }
    const pam = arr.map((item: any) => {
      return {
        infoId: item.id,
        infoNumber: item.numberId,
      }
    })
    cgData.value.map((item: any) => {
      item.stockInfo = pam
    })
    pageData.showAdd1 = false
  }

  const objectOP = reactive<any>({
    bigClassName1: '',
    bigClassName2: '',
    bigClassName3: '',
    bigName1: [],
    bigName2: [],
    bigName3: [],
  })

  //下拉框   物料大类
  // const WLfocusSel = (val: any) => {
  //   if (val === 1) {
  //     post({
  //       url: 'purchase/MaterialBigClass/getFieldValue',
  //           data: {"bigClassName":""},
  //     }).then(({ data, code }: any) => {
  //       if (code === 200) {
  //         objectOP.bigName1 = data
  //       } else {
  //         Message.error({
  //           content: '查询失败！',
  //           duration: 5000,
  //         })
  //       }
  //     })
  //   } else if (val === 2) {
  //     post({wms/ironwareOutStock/getIronwarePick
  //       // url: 'purchase/MaterialMiddleClass/getList',
  //       // data: { bigClassId: objectOP.bigName1.find((item: any) => item.bigClassName === objectOP.bigClassName1)?.id },
  //       url: 'purchase/MaterialMiddleClass/getFieldValue',
  //           data:{"middleClassName":"",filterMap:{"bigClassName": objectOP.bigName1.find((item: any) => item.bigClassName === objectOP.bigClassName1)?.id }}
  //     }).then(({ data, code }: any) => {
  //       if (code === 200) {
  //         objectOP.bigName2 = data
  //       } else {
  //         Message.error({
  //           content: '查询失败！',
  //           duration: 5000,
  //         })
  //       }
  //     })
  //   } else if (val === 3) {
  //     post({
  //       url: 'purchase/MaterialSubClass/getList',
  //       data: { middleClassId: objectOP.bigName2.find((item: any) => item.middleClassName === objectOP.bigClassName2)?.id },
  //     }).then(({ data, code }: any) => {
  //       if (code === 200) {
  //         objectOP.bigName3 = data
  //       } else {
  //         Message.error({
  //           content: '查询失败！',
  //           duration: 5000,
  //         })
  //       }
  //     })
  //   }
  // }
  const WLfocusSel = (val: any, eventVal: any = null) => {
    if (!eventVal) eventVal = ''
    if (val === 1) {
      post({
        url: 'purchase/MaterialBigClass/getFieldValue',
        data: { bigClassName: eventVal },
      }).then(({ data, code }: any) => {
        if (code === 200) {
          objectOP.bigName1 = data
        } else {
          Message.error({
            content: '查询失败！',
            duration: 5000,
          })
        }
      })
    } else if (val === 2) {
      post({
        url: 'purchase/MaterialMiddleClass/getFieldValue',
        // data: { bigClassId: objectOP.bigClassName1 },
        data: { middleClassName: eventVal, filterMap: { bigClassId: objectOP.bigClassName1 } },
      }).then(({ data, code }: any) => {
        if (code === 200) {
          objectOP.bigName2 = data
        } else {
          Message.error({
            content: '查询失败！',
            duration: 5000,
          })
        }
      })
    } else if (val === 3) {
      post({
        url: 'purchase/MaterialSubClass/getFieldValueFilter',
        // data: { middleClassId: objectOP.bigClassName2 },
        data: { subClassName: eventVal, filterMap: { middleClassId: objectOP.bigClassName2 } },
      }).then(({ data, code }: any) => {
        if (code === 200) {
          objectOP.bigName3 = data
        } else {
          Message.error({
            content: '查询失败！',
            duration: 5000,
          })
        }
      })
    }
  }
  const bigChange = (val: any) => {
    if (val === 1) {
      objectOP.bigName2 = []
      objectOP.bigClassName2 = ''
      objectOP.bigName3 = []
      objectOP.bigClassName3 = ''
    } else if (val === 2) {
      objectOP.bigName3 = []
      objectOP.bigClassName3 = ''
    }
  }

  // 下拉框  物料编码
  const WLfocusSel2 = () => {
    WLselCxAll2({ materialCode: '', auditState: 1 })
  }
  const WLoptions2 = ref<any>(pageData.codeList)
  const WLloading2 = ref(false)
  const WLhandleSearch2 = (value: any) => {
    if (value) {
      const ob = { materialCode: value, auditState: 1 }
      WLloading2.value = true
      WLselCxAll2(ob)
      WLoptions2.value = pageData.codeList
      WLloading2.value = false
    } else {
      WLoptions2.value = []
    }
  }
  function WLselCxAll2(val: any) {
    post({
      url: 'purchase/MaterialInfo/getFieldValue',
      data: val,
    }).then(({ data, code }: any) => {
      if (code === 200) {
        pageData.codeList = data
      } else {
        Message.error({
          content: '查询失败！',
          duration: 5000,
        })
      }
    })
  }
  const WLhandleCode = (e: any) => {
    materialCode.value = e.split('——')[0]
  }

  // 下拉框  物料名称
  const WLfocusSel3 = () => {
    WLselCxAll3({ materialName: '', auditState: 1 })
  }
  const WLoptions3 = ref<any>(pageData.wlNameList)
  const WLloading3 = ref(false)
  const WLhandleSearch3 = (value: any) => {
    if (value) {
      const ob = { materialName: value, auditState: 1 }
      WLloading3.value = true
      WLselCxAll3(ob)
      WLoptions3.value = pageData.wlNameList
      WLloading3.value = false
    } else {
      WLoptions3.value = []
    }
  }
  function WLselCxAll3(val: any) {
    post({
      url: 'purchase/MaterialInfo/getFieldValue',
      data: val,
    }).then(({ data, code }: any) => {
      if (code === 200) {
        pageData.wlNameList = data
      } else {
        Message.error({
          content: '查询失败！',
          duration: 5000,
        })
      }
    })
  }
  const WLhandleName = (e: any) => {
    materialName.value = e.split('——')[1]
  }

  // 下拉框  规格
  const WLfocusSel4 = () => {
    WLselCxAll4({ specName: '', auditState: 1 })
  }
  const WLoptions4 = ref<any>(pageData.specList)
  const WLloading4 = ref(false)
  const WLhandleSearch4 = (value: any) => {
    if (value) {
      const ob = { specName: value, auditState: 1 }
      WLloading4.value = true
      WLselCxAll4(ob)
      WLoptions4.value = pageData.specList
      WLloading4.value = false
    } else {
      WLoptions4.value = []
    }
  }
  function WLselCxAll4(val: any) {
    post({
      url: 'purchase/MaterialInfo/getFieldValue',
      data: val,
    }).then(({ data, code }: any) => {
      if (code === 200) {
        pageData.specList = data
      } else {
        Message.error({
          content: '查询失败！',
          duration: 5000,
        })
      }
    })
  }
  const { saveGridState: saveGridState01, updateGridState: updateGridState01 } =
    saveOrUpdateGridState01('OrderDeliveryList2-1', gridOption, colState, tc)
  const onColumnMoved = () => {
    saveGridState01()
  }
  const onColumnResized = () => {
    saveGridState01()
  }
  const onColumnVisible = () => {
    saveGridState01()
  }
  const { saveGridState: saveGridState02, updateGridState: updateGridState02 } =
    saveOrUpdateGridState02('OrderDeliveryList2-2', gridOption2, colState2, tc2)
  const onColumnMoved2 = () => {
    saveGridState02()
  }
  const onColumnResized2 = () => {
    saveGridState02()
  }
  const onColumnVisible2 = () => {
    saveGridState02()
  }

  const Query = () => {
    console.log('触发回车事件')
  }
</script>

<style scoped lang="less">
  :deep(.ag-cell-value) {
    user-select: initial;
    -moz-user-select: text;
    -ms-user-select: text;
    -webkit-user-select: text;
  }

  :deep(.arco-table-td-content) {
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
  }

  :deep(.ag-cell) {
    border-right: 1px solid #dde2eb;
  }

  :deep(.ag-header-cell) {
    border-right: 1px solid #dde2eb;
  }

  .cgisDatas {
    width: 50%;
    display: flex;
    justify-content: space-between;
  }

  .TTou {
    margin-top: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .TTou1 {
    margin-left: -228px;
  }

  .TTou2 {
    margin-left: 20px;
  }

  .DivFit {
    width: 100%;
    height: 20px;
    margin-left: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .DivFit div {
    float: left;
    width: 190px;
  }

  .isTable {
    margin: 50px;
    width: 90%;
    // margin: 0 auto;
    border: 1.2px solid #ccc;
    text-align: center;
    border-collapse: collapse;

    td {
      border: 1.2px solid #ccc;
    }

    th {
      border: 1.2px solid #ccc;
    }
  }

  :deep(.arco-picker input) {
    padding-left: 0 !important;
  }

  :deep(.arco-picker) {
    padding-left: 0 !important;
  }

  :deep(.arco-picker-separator) {
    padding: 0 !important;
  }
  :deep(.modal-full-h) {
    height: calc(100% - 113px) !important;
    // padding:0;
  }
</style>
